package com.wilson.treeviewer.model;

import java.util.ArrayList;
import java.util.List;

public class UserNode {

    private final User user;

    private UserNode parentNode;

    private final List<UserNode> children = new ArrayList<>();

    public UserNode(User user) {
        this.user = user;
    }

    public User getUser() {
        return user;
    }

    public UserNode getParentNode() {
        return parentNode;
    }

    public void setParentNode(UserNode parentNode) {
        this.parentNode = parentNode;
    }

    public List<UserNode> getChildren() {
        return children;
    }

    public void addChild(UserNode node) {
        children.add(node);
    }

    @Override
    public int hashCode() {
        return user.hashCode();
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof UserNode) {
            UserNode node = (UserNode) obj;
            return user.equals(node.getUser());
        }
        return false;
    }

    @Override
    public String toString() {
        return user.toString();
    }

}
